package com.ssy.mall.controller;

import com.github.pagehelper.PageInfo;
import com.ssy.mall.common.ApiRestResponse;
import com.ssy.mall.model.pojo.Product;
import com.ssy.mall.model.request.AddDetailById;
import com.ssy.mall.model.request.ProductListReq;
import com.ssy.mall.service.ProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 苏少有的idea
 * @date: 2022/1/4
 * @description 前台商品Controller
 */
@RestController
@CrossOrigin
public class ProductController {
    @Autowired
    private ProductService productService;

    @ApiOperation("商品详情")
    @PostMapping ("product/detail")
    public ApiRestResponse detail(@RequestBody AddDetailById addDetailById) {
        Product detail = productService.detail(addDetailById.getId());
        return ApiRestResponse.success(detail);

    }

    @ApiOperation("前台商品目录")
    @GetMapping("product/list")
    public ApiRestResponse list(ProductListReq productListReq) {
        PageInfo list = productService.list(productListReq);
        return ApiRestResponse.success(list);


    }

}
